<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page trimDirectiveWhitespaces="true" %>
<%String path = request.getContextPath();%>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="<%=path%>/static/layui/css/layui.css" rel="stylesheet">
    <link href="<%=path%>/static/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
</head>

<body>

<form class="layui-form" method="post"  action="<%=path%>/system/post/save" lay-filter="formDemo" style="margin-top: 40px;width: 600px;" id="data">
    <div class="layui-form-item">
        <label class="layui-form-label">隶属部门：</label>
        <div class="layui-input-block">
            <!--岗位id-->
            <input type="hidden"  id="id" name="id" value="<c:if test="${not empty edit}"> ${edit.id}</c:if>"/>
            <!--部门-->
            <input id="deptId" type="text" readonly="true"   autocomplete="off"
                   value=
                   "<c:choose>
                          <c:when test="${not empty edit}"> ${edit.deptId.name}</c:when>
                         <c:when test="${not empty parentAdd}"> ${parentAdd.deptId.name}</c:when>
                         <c:when test="${not empty add}"> ${add.deptId.name}</c:when>
                    </c:choose>"
                   data-id=
                       "<c:choose>
                           <c:when test="${not empty edit}"> ${edit.deptId.id}</c:when>
                         <c:when test="${not empty parentAdd}"> ${parentAdd.deptId.id}</c:when>
                         <c:when test="${not empty add}"> ${add.deptId.id}</c:when>
                        </c:choose>"
                   class="layui-input" onclick="deptIdTreeClick()" lay-verify="required">
            <input type="hidden" name="deptId.id" id="deptIdValue"
                   value="<c:choose>
                        <c:when test="${not empty edit}"> ${edit.deptId.id}</c:when>
                         <c:when test="${not empty parentAdd}"> ${parentAdd.deptId.id}</c:when>
                         <c:when test="${not empty add}"> ${add.deptId.id}</c:when>
                    </c:choose>">
        </div>
    </div>
    <!--岗位-->
    <div class="layui-form-item">
        <label class="layui-form-label">上级岗位：</label>
        <div class="layui-input-block">
            <input id="parentId" type="text" readonly="true"   autocomplete="off"
                   value=
                           "<c:choose>
                          <c:when test="${not empty edit}"> ${edit.parent.name}</c:when>
                         <c:when test="${not empty parentAdd}"> ${parentAdd.name}</c:when>
                         <c:when test="${not empty add}"> ${add.parent.name}</c:when>
                    </c:choose>"
                   data-id=
                           "<c:choose>
                           <c:when test="${not empty edit}"> ${edit.parent.id}</c:when>
                         <c:when test="${not empty parentAdd}"> ${parentAdd.id}</c:when>
                         <c:when test="${not empty add}"> ${add.parent.id}</c:when>
                        </c:choose>"
                   class="layui-input" onclick="parentIdTreeClick()" lay-verify="required">
            <input type="hidden" name="parentId" id="parentIdValue"
                   value="<c:choose>
                        <c:when test="${not empty edit}"> ${edit.parent.id}</c:when>
                         <c:when test="${not empty parentAdd}"> ${parentAdd.id}</c:when>
                         <c:when test="${not empty add}"> ${add.parent.id}</c:when>
                    </c:choose>">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">新增岗位名：</label>
        <div class="layui-input-block">
            <input type="text" name="name" autocomplete="off"
                   value="<c:if test="${not empty edit}"> ${edit.name}</c:if>"
                   class="layui-input"  lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">显示顺序：</label>
        <div class="layui-input-block">
            <input type="text" name="sort" autocomplete="off"
                   value="<c:if test="${not empty edit}"> ${edit.sort}</c:if>"
                   class="layui-input" id="parentId2" lay-verify="number">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">描述：</label>
        <div class="layui-input-block">
            <input type="text" name="description" autocomplete="off"
                   value="<c:if test="${not empty edit}"> ${edit.description}</c:if>"
                   class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">数据范围</label>
        <div class="layui-input-block">
            <select name="dataScope" lay-verify="required">
                <option value=""></option>
                <option value="0" <c:if test="${not empty edit}"> ${edit.right==0?"selected":""}</c:if>>自己</option>
                <option value="1" <c:if test="${not empty edit}"> ${edit.right==1?"selected":""}</c:if>>本部门</option>
                <option value="2" <c:if test="${not empty edit}"> ${edit.right==2?"selected":""}</c:if>>本部门及所有子部门</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">更新权限</label>
        <div class="layui-input-block">
            <select name="right" lay-verify="required">
                <option value=""></option>
                <option value="0" <c:if test="${not empty edit}"> ${edit.right==0?"selected":""}</c:if>>只查阅</option>
                <option value="1" <c:if test="${not empty edit}"> ${edit.right==1?"selected":""}</c:if>>可变更</option>
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">状态：</label>
        <div class="layui-input-block">
            <input type="checkbox" name="enable" lay-skin="switch" lay-text="正常|禁用" value="0"
             <c:if test="${not empty edit && edit.enable==0}">checked</c:if>
            >
        </div>
    </div>
    <!--录入人-->
    <input type="hidden" name="inputPersonId.id"
           value="<c:if test="${not empty  user}">${user.id}</c:if>"
    >
    <button id="departSubmit" class="layui-btn" lay-filter="formVerify" lay-submit style="display: none">添加</button>

</form>
<script src="<%=path%>/static/layui/layui.all.js"></script>
<script src="<%=path%>/static/js/jquery.min.js?v=2.1.4"></script>
<script src="<%=path%>/static/myjs/MyLayer.js"></script>
<script>
//初始化
var layer=window.top.layer;
layui.use(['form'], function () {
    let form=layui.form
    form.on('submit(formDemo)', function(data){
        let brotherIframe=parent[parent.length-2]
        brotherIframe.renderTable();
        layer.closeAll("iframe")
    });
})

//点击显示部门树
function deptIdTreeClick() {
    MyLayer.iframeLayer(layer,"请选择隶属部门","<%=path%>/system/department/departmentTree",{
        "确定":function (index) {
            let brotherIframe=parent['layui-layer-iframe' +index]
            let node=brotherIframe.myTree.getSelectedNodes();
            if (node.length==0){
                return true;
            }
            let obj=node[0];
            //设置部门时清空岗位
            window.$("#deptId").val(obj.name)
            window.$("#deptIdValue").val(obj.id)
            window.$("#parentId").val("")
            window.$("#parentIdValue").val("")
        }
    },"small")
}
//点击显示岗位树(根据部门id)
function parentIdTreeClick() {
    //部门id
    let deptId= window.$("#deptIdValue").val()
    //当前岗位id
    let id= window.$("#id").val()
    if(deptId===undefined||deptId===""){
        layer.msg("请先选择部门！",{
            zIndex: layer.zIndex, //重点1
            success: function(layero){
                layer.setTop(layero); //重点2
            }
        });
        return
    }
    MyLayer.iframeLayer(layer,"请选择上级岗位","<%=path%>/system/post/postTree?id="+id+"&deptId="+deptId,{
        "确定":function (index) {
            let brotherIframe=parent['layui-layer-iframe' +index]
            let node=brotherIframe.myTree.getSelectedNodes();
            if (node.length==0){
                return true;
            }
            let obj=node[0];
            window.$("#parentId").val(obj.name)
            window.$("#parentIdValue").val(obj.id)
        }
    },"small")
}
//点击显示用户表
function userClick() {
    MyLayer.iframeLayer(layer,"请选择负责人","<%=path%>/system/department/departmentUsers",{
        "确定":function (index) {
            let brotherIframe=parent['layui-layer-iframe' +index]
            let data=brotherIframe.table.checkStatus('userTable').data;

            if (data.length===0){
                return  true;
            }
            window.$("#deptUser").val(data[0].name)
            window.$("#deptUserValue").val(data[0].id)
        }
    },"small")
}

</script>
</body>

</html>